#include <stdio.h>
#include <string.h>
#define LEN_NAME    100
#define LEN_PSW     100
#define LEN_UID     100
#define LEN_PATH    100
#define LEN_STR     1024


int main()
{
    const char* url = "p2pstream://username:password@QWERTY/ch0.ts";
    char username[LEN_NAME];
    char password[LEN_PSW];
    char uid[LEN_UID];
    char path[LEN_PATH];

    char str[LEN_STR];
    const char* sstr;
    int n;

    size_t size = snprintf(str, LEN_STR, "p2pstream://%%%d[^:]:%%%d[^@]@%%%d[^/]%%%ds", LEN_NAME-1, LEN_PSW-1, LEN_UID-1, LEN_PATH-1);
    str[size] = '\0';

    const char* strs[] = {
#if 0
        "p2pstream://%s:%s@%s%s", 
        "p2pstream://%[^:]s:%[^@]s@%[^/]s%s",
        "p2pstream://%[^:]*:%[^@]*@%[^/]*%s",
        "p2pstream://%[^:].:%[^@].@%[^/].%s",
        "p2pstream://%[^:]:%[^@]@%[^/]%s"
#endif
        str
    };

    int i;
    int nstrs = sizeof(strs)/sizeof(strs[0]);
    for(i=0; i<nstrs; i++) {

        memset(username, 0, sizeof(username));
        memset(password, 0, sizeof(password));
        memset(uid, 0, sizeof(uid));
        memset(path, 0, sizeof(path));
        sstr = strs[i];
        n = sscanf(url, sstr, username, password, uid, path);
        printf("-%-10s = %s\n", "sstr", sstr);
        printf(" %-10s = %d\n", "n", n);
        printf(" %-10s = %s\n", "username", username);
        printf(" %-10s = %s\n", "password", password);
        printf(" %-10s = %s\n", "uid", uid);
        printf(" %-10s = %s\n\n", "path", path);
    
    }

    return 0;
}
